package com.loveling.controller;

import com.loveling.entity.RedisDemoInfo;
import com.loveling.service.RedisDemoInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 * User: liangjiefa
 * Date: 2017/6/12 23:24
 * To change this template use File | Settings | File Templates.
 */
@RestController
public class RedisDemoInfocontroller {

    @Autowired
    private RedisDemoInfoService redisDemoInfoService;

    @RequestMapping("/test")
    public String test() {
        RedisDemoInfo redisDemoInfo = redisDemoInfoService.findById(1);
        System.out.println("loaded=" + redisDemoInfo);
        RedisDemoInfo cached = redisDemoInfoService.findById(1);
        System.out.println("cached=" + cached);
        redisDemoInfo = redisDemoInfoService.findById(2);
        System.out.println("loaded2=" + redisDemoInfo);
        return "ok";
    }

    @RequestMapping("/delete")
    public String delete(long id) {
        redisDemoInfoService.deleteFromCache(id);
        return "ok";
    }

    @RequestMapping("/test1")
    public String test1() {
        redisDemoInfoService.test();
        System.out.println("DemoInfoController.test1()");
        return "ok";
    }

}
